//
//  JSMDreamCityTableViewCell.m
//  TakeYouTourTogether
//
//  Created by king on 15/11/30.
//  Copyright © 2015年 king. All rights reserved.
//

#import "JSMDreamCityTableViewCell.h"

@implementation JSMDreamCityTableViewCell

#pragma mark - Method initWithStyle:reuseIdentifier:
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}
#pragma mark - Method createView
- (void)createView {
    self.mainImageView = [[BaseImageView alloc] init];
    [self.contentView addSubview:self.mainImageView];
    self.mainImageView.backgroundColor = [UIColor clearColor];
    //    self.mainImageView.layer.borderWidth = 1;
    
    self.titleLabel = [[BaseLabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    //    self.titleLabel.layer.borderWidth = 1;
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.backgroundColor = [UIColor clearColor];
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont boldSystemFontOfSize:19];
    self.titleLabel.alpha = 1;
}
#pragma mark - Method layoutSubviews
- (void)layoutSubviews {
    [super layoutSubviews];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    [self.mainImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(5, 10, 5, 10));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mainImageView);
        make.bottom.equalTo(self.mainImageView.mas_bottom);
        make.width.mas_equalTo(self.mainImageView);
        make.height.mas_equalTo(40*ALLEDITIONHEIGHT);
    }];
}
#pragma mark - Method setModel:
- (void)setModel:(JSMDreamCityModel *)model {
    if (_model != model) {
        _model = model;
    }
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:model.imageUrl] placeholderImage:[UIImage imageNamed:PLACE_HOLDER_IMAGE]];
    self.titleLabel.text = model.name;
    self.titleLabel.backgroundColor = [UIColor colorWithRed:0.946 green:0.905 blue:0.900 alpha:0.550];
    [self.titleLabel sizeToFit];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}
#pragma mark - Method setPrefectureModel:
- (void)setPrefectureModel:(JSMDreamCityPrefectureModel *)prefectureModel {
    if (_prefectureModel != prefectureModel) {
        _prefectureModel = prefectureModel;
    }
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:prefectureModel.url] placeholderImage:[UIImage imageNamed:PLACE_HOLDER_IMAGE]];
    self.titleLabel.text = prefectureModel.name;
    self.titleLabel.backgroundColor = [UIColor colorWithRed:0.946 green:0.905 blue:0.900 alpha:0.550];
    [self.titleLabel sizeToFit];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

@end
